package com.financing.wap.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.financing.wap.dao.IForegroundProductDao;
import com.financing.wap.dao.IProductSupplierDao;
import com.financing.wap.dto.ForegroundProductDTO;
import com.financing.wap.dto.ProductSupplierDTO;
import com.financing.wap.service.IProductSupplierService;

@Service("productSupplierService")
public class ProductSupplierServiceImpl implements IProductSupplierService{
	
	@Autowired
	private IProductSupplierDao productSupplierDao;
	
	@Autowired
	private IForegroundProductDao foregroundProductDao;

	@Override
	public int addProductSupplier(ProductSupplierDTO productSupplierDto) {
		return productSupplierDao.addProductSupplier(productSupplierDto);
	}

	@Override
	public List<ProductSupplierDTO> queryProductSupplier(
			ProductSupplierDTO productSupplierDto) {
		return productSupplierDao.queryProductSupplier(productSupplierDto);
	}

	@Override
	@Transactional(rollbackFor={Exception.class,RuntimeException.class})
	public int addProductSupplierAndProduct(
			ProductSupplierDTO productSupplierDto,
			ForegroundProductDTO foregroundProductDto) {
		if(productSupplierDto.getId()==null){
			//新增供应方
			productSupplierDao.addProductSupplier(productSupplierDto);
		}
		foregroundProductDto.setFaId(productSupplierDto.getFaId());
		foregroundProductDto.setCheckStatus("0");
		int update=foregroundProductDao.addForegroundProduct(foregroundProductDto);
		
		return update;
	}
	
	@Override
	public int updateForegroundProduct(ForegroundProductDTO foregroundProductDto){
		return foregroundProductDao.updateForegroundProduct(foregroundProductDto);
	}

	@Override
	public int updateProductSupplier(ProductSupplierDTO productSupplierDto) {
		return productSupplierDao.updateProductSupplier(productSupplierDto);
	}

}
